import router from './router';
// import { ElMessage } from 'element-plus'
// import NProgress from 'nprogress'
// import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth';
import { isHttp } from '@/utils/validate';
import { isRelogin } from '@/utils/request';
import { showNotify } from 'vant';
import cache from '@/utils/cache';
// import useUserStore from '@/store/modules/user'
// import useSettingsStore from '@/store/modules/settings'
// import usePermissionStore from '@/store/modules/permission'

import useStore from '@/store/index';
import { storeToRefs } from 'pinia';

const whiteList = ['error', '/', 'login'];

router.beforeEach((to, from, next) => {
  // const { setting } = useStore();


  if (cache.local.getTokenloc()) {
    next()
  } else {
    // 没有token
    if (whiteList.indexOf(to.path) > -1 || whiteList.indexOf(to.name) > -1) {
      next();
    } else {
      showNotify({
        type: 'danger',
        message: '无效的会话，或者会话已过期，请重新登录。'
      });
      next({ name: 'login' }); // 否则全部重定向到登录页
      NProgress.done();
    }
  }
});

router.afterEach(() => {
  // NProgress.done()
});
